package com.qinsoft.frame.taobao.onsale;

import java.util.List;

import org.directwebremoting.WebContextFactory;

import com.qinsoft.business.onsale.bean.OnSale;
import com.qinsoft.business.onsale.dao.OnSaleDao;
import com.qinsoft.business.onsalelog.bean.OnSaleLog;
import com.qinsoft.business.onsalelog.dao.OnSaleLogDao;
import com.qinsoft.frame.common.UserUtil;

public class OnSaleService 
{
	private String sessionId = WebContextFactory.get().getSession().getId();
	private String nick = UserUtil.getInstance().getUserInfo(sessionId).getNick();
	/**
	 * 保存上下架计划
	 */
	public void savePlan(String plan[][],Long itemNum)
    {
	    OnSaleDao saleDao = new OnSaleDao();
	    OnSale onsale = new OnSale(nick,true,itemNum,plan);
	    saleDao.save(onsale);
    }
    
	/**
	 * 读取上下架计划
	 */
    public OnSale getPlan()
    {
        OnSaleDao saleDao = new OnSaleDao();
        OnSale onsale = saleDao.select(nick);
        return onsale;
    }
    
    /**
     * 查看日志
     */
    public List<OnSaleLog> getLog()
    {
        OnSaleLogDao logDao = new OnSaleLogDao();
        return logDao.select(nick);
    }
    
    /**
     * 查看详细日志
     */
    public List<OnSaleLog> select(Long begin,Long total){
        if(total!=0){
            OnSaleLogDao logDao = new OnSaleLogDao();
            return logDao.selectAll(nick,begin);
        }
        else{
            return null;
        }
    }
    
    /**
     * 查询日志总数
     */
    public Long count(){
        OnSaleLogDao logDao = new OnSaleLogDao();
        return logDao.count(nick);
    }
}
